//
//  DHFirstTableViewCell.m
//  Moment
//
//  Created by dllo on 15/12/25.
//  Copyright © 2015年 片刻. All rights reserved.
//

#import "DHFirstTableViewCell.h"

@implementation DHFirstTableViewCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createViews];
    }
    return self;
}
-(void)createViews{
    _userImageView = [[UIImageView alloc]init];
    [self.contentView addSubview:_userImageView];
    _userNameLabel = [[UILabel alloc]init];
    [self.contentView addSubview:_userNameLabel];
    _coverImageView = [[UIImageView alloc]init];
    [self.contentView addSubview:_coverImageView];
    _describeLabel = [[UILabel alloc]init];
    [self.contentView addSubview:_describeLabel];
    _soundImageView = [[UIImageView alloc]init];
    [self.contentView addSubview:_soundImageView];
    _soundCountLabel = [[UILabel alloc]init];
    [self.contentView addSubview:_soundCountLabel];
}
-(void)setRadioInfo:(DHRadioInfo *)radioInfo{
    if (_radioInfo != radioInfo) {
        _radioInfo = radioInfo;
    }
    if (_radioInfo.userInfo != NULL) {
        [_userImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@(SCREEN_WIDTH * 0.04));
            
            make.top.equalTo(@(SCREEN_WIDTH * 0.04));
            make.height.and.width.equalTo(self.contentView.mas_width).multipliedBy(0.08);
        }];

        _userImageView.layer.cornerRadius = SCREEN_WIDTH * 0.08/2;
        _userImageView.layer.masksToBounds = YES;
      
        _userImageView.layer.borderWidth = 0.1;
        _userImageView.layer.borderColor = [UIColor colorWithWhite:0.632 alpha:1.000].CGColor;
        NSURL *url = [NSURL URLWithString:_radioInfo.userInfo.icon];
        [_userImageView sd_setImageWithURL:url placeholderImage:PLACEHOLDER_IMAGE];
       [_describeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
           make.top.equalTo(_userImageView.mas_bottom).offset((SCREEN_WIDTH * 0.08/2));
           make.left.equalTo(@(SCREEN_WIDTH * 0.04));
           make.bottom.equalTo(@(-(SCREEN_WIDTH * 0.04)));
           make.right.equalTo(@(-(SCREEN_WIDTH * 0.04)));
        }];
   
        
        [_userNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_userImageView.mas_right).offset(3);
            make.top.equalTo(@(SCREEN_WIDTH * 0.04));
            make.height.equalTo(_userImageView.mas_height);
            make.width.equalTo(_userImageView.mas_width).multipliedBy(2);
         }];
    CGSize size = CGSizeMake(MAXFLOAT, 20);
        UIFont *font = [UIFont systemFontOfSize:9];
    CGSize height = [SelfAdaption labelRectWithSize:size LabelText:[NSString stringWithFormat:@"%ld",_radioInfo.musicvisitnum] Font:font];
        [_soundCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(@(SCREEN_WIDTH * 0.04));
            make.right.equalTo(@(-SCREEN_WIDTH * 0.045));
            make.height.equalTo(_userNameLabel.mas_height);
            make.width.equalTo(@(height.width));
        }];
        
        [_soundImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(_soundCountLabel.mas_left).offset(-3);
            make.top.equalTo(_soundCountLabel.mas_top).offset(SCREEN_WIDTH * 0.016);
            make.bottom.equalTo(_soundCountLabel.mas_bottom).offset(-SCREEN_WIDTH * 0.016);
            make.width.equalTo(_soundImageView.mas_height);
         }];
        
        }
    _soundCountLabel.text = [NSString stringWithFormat:@"%ld",_radioInfo.musicvisitnum];
    _soundCountLabel.font = [UIFont systemFontOfSize:8];
    _soundImageView.image = [UIImage imageNamed:@"iconfont-shengyin"];

  
    _describeLabel.text = _radioInfo.desc;
    _describeLabel.font = [UIFont systemFontOfSize:12];
    _describeLabel.textColor = [UIColor colorWithWhite:0.234 alpha:1.000];
    _userNameLabel.text = _radioInfo.userInfo.uname;
    _userNameLabel.font = [UIFont systemFontOfSize:10];
    _userNameLabel.textColor = [UIColor colorWithRed:0.708 green:0.818 blue:0.867 alpha:1.000];
    _soundCountLabel.textColor = [UIColor grayColor];
    
   }
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
